/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { isLegalData } from '@/utils/utils';
import { message } from 'antd';
import request from '../utils/request';

/** 代入库，列表 */
export async function getMixInList(params) {
  return request('/Api/YZ/League/complate', {
    method: 'POST',
    body: params,
  }).then(res => {
    const { code, data = {}, msg } = res;
    const { list, total } = data || {};
    if (code != 0) {
      message.error(msg);
    }
    return {
      list: isLegalData(list),
      total,
    };
  });
}
/** 代入库，获取弹窗配置 */
export async function getMixInDetail(params) {
  return request('/Api/YZ/League/complateDetail', {
    method: 'POST',
    body: params,
  }).then(res => {
    const { data = [], msg } = res;
    const { info = [], phone, cm_id, platform_brand = {} } = data || {};
    const arr = [];
    Object.keys(platform_brand).forEach(v => {
      arr.push({
        label: platform_brand[v],
        value: v,
      });
    });
    const resData = {
      phone,
      cm_id,
      info: [],
      platform_brand: arr,
      brands: platform_brand,
    };

    if (res.code == 0) {
      isLegalData(info).forEach(item => {
        const { status } = item;
        item.checked = Boolean(status == 1);
      });
      resData.info = info;
      return resData;
    }
    message.error(msg);
    return resData;
  });
}
/** 代入库，新增或修改 */
export async function addMixedIn(params) {
  return request('/Api/YZ/League/complateAdd', {
    method: 'POST',
    body: params,
  });
}

/** 场地扫描管理，快递员列表 */
export async function getSiteScanList(params) {
  return request('/Api/YZ/League/sitescan', {
    method: 'POST',
    body: params,
  }).then(res => {
    const { code, data = {}, msg } = res;
    const { list, total } = data || {};
    if (code != 0) {
      message.error(msg);
    }
    return {
      list: isLegalData(list),
      total,
    };
  });
}

/** 场地扫描管理，添加快递员 */
export async function siteScanAdd(params) {
  return request('/Api/YZ/League/sitescanAdd', {
    method: 'POST',
    body: params,
  });
}
/** 场地扫描管理，快递员启用/禁用 */
export async function siteScanEdit(params) {
  return request('/Api/YZ/League/sitescanEdit', {
    method: 'POST',
    body: params,
  });
}
/** 场地扫描管理，货架设置框数量详情 */
export async function getFrameDetail(params) {
  return request('/Api/YZ/League/frameDetail', {
    method: 'POST',
    body: params,
  });
}
/** 场地扫描管理，货架框数量设置 */
export async function frameEdit(params) {
  return request('/Api/YZ/League/frameEdit', {
    method: 'POST',
    body: params,
  });
}
/** 代入库，发送短信验证码 */
export async function getSmsCode(params) {
  return request('/Api/YZ/League/sendSmsCode', {
    method: 'POST',
    body: params,
  });
}
